import { _ as _export_sfc, x as useMainStore, y as storeToRefs, z as ref, al as useNavbarHeight, U as onShow, R as onPullDownRefresh, O as watch, W as stopPullDownRefresh, g as createElementBlock, b as createVNode, w as withCtx, n as normalizeStyle, H as unref, F as Fragment, j as resolveEasycom, i as index$g, G as __easycom_0, k as resolveDynamicComponent, o as openBlock, ae as Input, Q as index$x, t as createTextVNode, h as renderList, c as createBlock, f as normalizeClass, u as toDisplayString, P as ScrollView, e as createCommentVNode, p as index$q, s as index$i, X as formatDateTime, M as withModifiers, I as switchTab, ag as navigateBack } from './index-Cc4oxzDN.js';
import { _ as __easycom_4 } from './uv-empty.ob-CT4XT.js';
import { _ as __easycom_8 } from './modal._6MPzui9.js';
import { b as __easycom_5 } from './uv-toast.nS_Liirv.js';
import { c as couponMine, a as couponIndexApi, b as couponReceive } from './coupon.DpWQn5v_.js';
import './uv-loading-icon.DuNkB54M.js';

const _sfc_main = {
  __name: 'coupons',
  setup(__props) {

const main = useMainStore();
const { isLogin } = storeToRefs(main);
const title = ref('优惠券');

// 获取导航栏高度
const { navbarHeightCss } = useNavbarHeight();

	// 返回上一页
	const $onClickLeft = () => {
		navigateBack();
	};

const tabs = ref([
	{title: '我的优惠券', page:1, pagesize:10,
		coupons: []
	},
	{title: '未领优惠券', page:1, pagesize:10,
		coupons: []
	}
]);
const activeTabIndex = ref(0);
const detailModalVisible = ref(false);
const coupon = ref({});
const couponIndex = ref(0);
const exchange_code = ref('');
const uToast = ref();
const myCoupons = ref([]);
const notCoupons = ref([]);

onShow(() => {
	getCoupons(0);
});
onPullDownRefresh(() => {
	if(activeTabIndex.value == 0) {
		myCoupons.value = [];
	}
	if(activeTabIndex.value == 1) {
		notCoupons.value = [];
	}
	tabs.value[activeTabIndex.value].page = 1;
	getCoupons(activeTabIndex.value);
});
watch(activeTabIndex, () => {
   getCoupons(activeTabIndex.value);
});

// 兑换
const exchange = async() => {
	let data = await couponReceive({code:exchange_code.value});
	if (data) {
		uToast.value.show({
			message: '兑换成功',
			type: 'success'
		});
		tabs.value[0].coupons = [];
		tabs.value[0].page = 1;
		getCoupons(0);
		tabs.value[1].coupons = [];
		tabs.value[1].page = 1;
		getCoupons(1);
	}
};
// 使用范围
const typeInfo = (type) => {
	if (type == 0) {
		return '通用'
	}
	if (type == 1) {
		return '自取'
	}
	if (type == 2) {
		return '外卖'
	}
};
const handleTab = (index) => {
	console.log('activeTabIndex2:',index);
	activeTabIndex.value = index;
};
const getCoupons = async(type) => {
	let page = tabs.value[type].page;
	let pagesize = tabs.value[type].pagesize;
	if (type == 0) {
		myCoupons.value = await couponMine({page:page,pagesize:pagesize});
	}
	// 未领优惠券
	if (type == 1) {
		notCoupons.value = await couponIndexApi({page:page,pagesize:pagesize});
	}
	//console.log('data:',data)
	stopPullDownRefresh();
	
	console.log('tabs.value:',tabs.value[type].title);
	//tabs.value[type].page++;
};
const openDetailModal = (coupon,index) => {
	couponIndex.value = index;
	coupon.value = coupon;
	detailModalVisible.value = true;
};
const useCouponWith = (coupon) => {
	//coupon.value = coupon
	useCoupon();
};
const closeDetailModal = () => {
	detailModalVisible.value = false;
	coupon.value = {};
};
const useCoupon = () => {
	switchTab({
		url: '/pages/menu/menu'
	});
};
// 领取优惠券
const receive = async(coupon,index) => {
	let data = await couponReceive({id:coupon.id});
	if (data) {
		uToast.value.show({
			message: '领取成功',
			type: 'success'
		});
		detailModalVisible.value = false;
	}
};



return (_ctx, _cache) => {
  const _component_uv_navbar = resolveEasycom(resolveDynamicComponent("uv-navbar"), __easycom_0);
  const _component_v_uni_input = Input;
  const _component_v_uni_button = index$x;
  const _component_v_uni_view = index$g;
  const _component_uv_empty = resolveEasycom(resolveDynamicComponent("uv-empty"), __easycom_4);
  const _component_v_uni_image = index$q;
  const _component_v_uni_text = index$i;
  const _component_v_uni_scroll_view = ScrollView;
  const _component_modal = resolveEasycom(resolveDynamicComponent("modal"), __easycom_8);
  const _component_uv_toast = resolveEasycom(resolveDynamicComponent("uv-toast"), __easycom_5);

  return (openBlock(), createElementBlock(Fragment, null, [
    createVNode(_component_uv_navbar, {
      fixed: true,
      title: title.value,
      "left-arrow": "",
      onLeftClick: $onClickLeft
    }, null, 8, ["title"]),
    createVNode(_component_v_uni_view, {
      class: "container position-relative w-100 h-100 overflow-hidden",
      style: normalizeStyle(`padding-top: ${unref(navbarHeightCss)};`)
    }, {
      default: withCtx(() => [
        createVNode(_component_v_uni_view, { class: "exchange-box" }, {
          default: withCtx(() => [
            createVNode(_component_v_uni_view, { class: "input-box" }, {
              default: withCtx(() => [
                createVNode(_component_v_uni_input, {
                  type: "text",
                  modelValue: exchange_code.value,
                  "onUpdate:modelValue": _cache[0] || (_cache[0] = $event => ((exchange_code).value = $event)),
                  placeholder: "请输入兑换码",
                  "placeholder-class": "text-color-assist font-size-base"
                }, null, 8, ["modelValue"]),
                createVNode(_component_v_uni_button, {
                  type: "primary",
                  onClick: exchange
                }, {
                  default: withCtx(() => [
                    createTextVNode("兑换")
                  ]),
                  _: 1
                })
              ]),
              _: 1
            })
          ]),
          _: 1
        }),
        createVNode(_component_v_uni_view, { class: "tabbar" }, {
          default: withCtx(() => [
            (openBlock(true), createElementBlock(Fragment, null, renderList(tabs.value, (item, index) => {
              return (openBlock(), createBlock(_component_v_uni_view, {
                class: normalizeClass(["tab", {active: activeTabIndex.value == index}]),
                key: index,
                onClick: $event => (handleTab(index))
              }, {
                default: withCtx(() => [
                  createVNode(_component_v_uni_view, { class: "title" }, {
                    default: withCtx(() => [
                      createTextVNode(toDisplayString(item.title), 1)
                    ]),
                    _: 2
                  }, 1024)
                ]),
                _: 2
              }, 1032, ["class", "onClick"]))
            }), 128))
          ]),
          _: 1
        }),
        createVNode(_component_v_uni_view, { class: "flex-fill" }, {
          default: withCtx(() => [
            createVNode(_component_v_uni_scroll_view, {
              "scroll-y": "",
              class: "coupon-list",
              onScrolltolower: _cache[5] || (_cache[5] = $event => (getCoupons(activeTabIndex.value)))
            }, {
              default: withCtx(() => [
                (0 === activeTabIndex.value)
                  ? (openBlock(), createBlock(_component_v_uni_view, {
                      key: 0,
                      class: "wrapper"
                    }, {
                      default: withCtx(() => [
                        (myCoupons.value.length == 0)
                          ? (openBlock(), createBlock(_component_uv_empty, {
                              key: 0,
                              mode: "list"
                            }))
                          : createCommentVNode("", true),
                        (openBlock(true), createElementBlock(Fragment, null, renderList(myCoupons.value, (item, index) => {
                          return (openBlock(), createBlock(_component_v_uni_view, {
                            class: "coupon",
                            key: index,
                            onClick: $event => (openDetailModal(item,index))
                          }, {
                            default: withCtx(() => [
                              createVNode(_component_v_uni_view, { class: "taobao" }, {
                                default: withCtx(() => [
                                  createVNode(_component_v_uni_view, { class: "ticket" }, {
                                    default: withCtx(() => [
                                      createVNode(_component_v_uni_view, { class: "left" }, {
                                        default: withCtx(() => [
                                          createVNode(_component_v_uni_image, {
                                            class: "picture",
                                            src: item.image,
                                            mode: "aspectFill"
                                          }, null, 8, ["src"]),
                                          createVNode(_component_v_uni_view, { class: "introduce" }, {
                                            default: withCtx(() => [
                                              createVNode(_component_v_uni_view, { class: "top" }, {
                                                default: withCtx(() => [
                                                  createTextVNode(" ￥ "),
                                                  createVNode(_component_v_uni_text, { class: "big" }, {
                                                    default: withCtx(() => [
                                                      createTextVNode(toDisplayString(item.value), 1)
                                                    ]),
                                                    _: 2
                                                  }, 1024),
                                                  createVNode(_component_v_uni_view, null, {
                                                    default: withCtx(() => [
                                                      createTextVNode(" 满" + toDisplayString(item.least) + "减" + toDisplayString(item.value), 1)
                                                    ]),
                                                    _: 2
                                                  }, 1024)
                                                ]),
                                                _: 2
                                              }, 1024),
                                              createVNode(_component_v_uni_view, { class: "type" }, {
                                                default: withCtx(() => [
                                                  createTextVNode(toDisplayString(item.title), 1)
                                                ]),
                                                _: 2
                                              }, 1024),
                                              createVNode(_component_v_uni_view, { class: "date u-line-1" }, {
                                                default: withCtx(() => [
                                                  createTextVNode(toDisplayString(unref(formatDateTime)(item.startTime, 'yyyy-MM-dd')) + "-" + toDisplayString(unref(formatDateTime)(item.endTime, 'yyyy-MM-dd')), 1)
                                                ]),
                                                _: 2
                                              }, 1024)
                                            ]),
                                            _: 2
                                          }, 1024)
                                        ]),
                                        _: 2
                                      }, 1024),
                                      (activeTabIndex.value == 1)
                                        ? (openBlock(), createBlock(_component_v_uni_view, {
                                            key: 0,
                                            class: "right",
                                            onClick: _cache[1] || (_cache[1] = withModifiers(() => {}, ["stop"]))
                                          }, {
                                            default: withCtx(() => [
                                              createVNode(_component_v_uni_view, {
                                                class: "use immediate-use",
                                                round: true,
                                                onClick: $event => (receive(item, index))
                                              }, {
                                                default: withCtx(() => [
                                                  createTextVNode("立即领取")
                                                ]),
                                                _: 2
                                              }, 1032, ["onClick"])
                                            ]),
                                            _: 2
                                          }, 1024))
                                        : createCommentVNode("", true),
                                      (activeTabIndex.value == 0)
                                        ? (openBlock(), createBlock(_component_v_uni_view, {
                                            key: 1,
                                            class: "right",
                                            onClick: _cache[2] || (_cache[2] = withModifiers(() => {}, ["stop"]))
                                          }, {
                                            default: withCtx(() => [
                                              (item.status == 0)
                                                ? (openBlock(), createBlock(_component_v_uni_view, {
                                                    key: 0,
                                                    class: "use immediate-use",
                                                    round: true,
                                                    onClick: $event => (useCouponWith(item))
                                                  }, {
                                                    default: withCtx(() => [
                                                      createTextVNode("立即使用")
                                                    ]),
                                                    _: 2
                                                  }, 1032, ["onClick"]))
                                                : (openBlock(), createBlock(_component_v_uni_view, {
                                                    key: 1,
                                                    class: "used"
                                                  }, {
                                                    default: withCtx(() => [
                                                      createTextVNode("已使用")
                                                    ]),
                                                    _: 1
                                                  }))
                                            ]),
                                            _: 2
                                          }, 1024))
                                        : createCommentVNode("", true)
                                    ]),
                                    _: 2
                                  }, 1024)
                                ]),
                                _: 2
                              }, 1024)
                            ]),
                            _: 2
                          }, 1032, ["onClick"]))
                        }), 128))
                      ]),
                      _: 1
                    }))
                  : createCommentVNode("", true),
                (1 === activeTabIndex.value)
                  ? (openBlock(), createBlock(_component_v_uni_view, {
                      key: 1,
                      class: "wrapper"
                    }, {
                      default: withCtx(() => [
                        (notCoupons.value.length == 0)
                          ? (openBlock(), createBlock(_component_uv_empty, {
                              key: 0,
                              mode: "list"
                            }))
                          : createCommentVNode("", true),
                        (openBlock(true), createElementBlock(Fragment, null, renderList(notCoupons.value, (item, index) => {
                          return (openBlock(), createBlock(_component_v_uni_view, {
                            class: "coupon",
                            key: index,
                            onClick: $event => (openDetailModal(item,index))
                          }, {
                            default: withCtx(() => [
                              createVNode(_component_v_uni_view, { class: "taobao" }, {
                                default: withCtx(() => [
                                  createVNode(_component_v_uni_view, { class: "ticket" }, {
                                    default: withCtx(() => [
                                      createVNode(_component_v_uni_view, { class: "left" }, {
                                        default: withCtx(() => [
                                          createVNode(_component_v_uni_image, {
                                            class: "picture",
                                            src: item.image,
                                            mode: "aspectFill"
                                          }, null, 8, ["src"]),
                                          createVNode(_component_v_uni_view, { class: "introduce" }, {
                                            default: withCtx(() => [
                                              createVNode(_component_v_uni_view, { class: "top" }, {
                                                default: withCtx(() => [
                                                  createTextVNode(" ￥ "),
                                                  createVNode(_component_v_uni_text, { class: "big" }, {
                                                    default: withCtx(() => [
                                                      createTextVNode(toDisplayString(item.value), 1)
                                                    ]),
                                                    _: 2
                                                  }, 1024),
                                                  createVNode(_component_v_uni_view, null, {
                                                    default: withCtx(() => [
                                                      createTextVNode(" 满" + toDisplayString(item.least) + "减" + toDisplayString(item.value), 1)
                                                    ]),
                                                    _: 2
                                                  }, 1024)
                                                ]),
                                                _: 2
                                              }, 1024),
                                              createVNode(_component_v_uni_view, { class: "type" }, {
                                                default: withCtx(() => [
                                                  createTextVNode(toDisplayString(item.title), 1)
                                                ]),
                                                _: 2
                                              }, 1024),
                                              createVNode(_component_v_uni_view, { class: "date u-line-1" }, {
                                                default: withCtx(() => [
                                                  createTextVNode(toDisplayString(unref(formatDateTime)(item.startTime, 'yyyy-MM-dd')) + "-" + toDisplayString(unref(formatDateTime)(item.endTime, 'yyyy-MM-dd')), 1)
                                                ]),
                                                _: 2
                                              }, 1024)
                                            ]),
                                            _: 2
                                          }, 1024)
                                        ]),
                                        _: 2
                                      }, 1024),
                                      (activeTabIndex.value == 1)
                                        ? (openBlock(), createBlock(_component_v_uni_view, {
                                            key: 0,
                                            class: "right",
                                            onClick: _cache[3] || (_cache[3] = withModifiers(() => {}, ["stop"]))
                                          }, {
                                            default: withCtx(() => [
                                              createVNode(_component_v_uni_view, {
                                                class: "use immediate-use",
                                                round: true,
                                                onClick: $event => (receive(item, index))
                                              }, {
                                                default: withCtx(() => [
                                                  createTextVNode("立即领取")
                                                ]),
                                                _: 2
                                              }, 1032, ["onClick"])
                                            ]),
                                            _: 2
                                          }, 1024))
                                        : createCommentVNode("", true),
                                      (activeTabIndex.value == 0)
                                        ? (openBlock(), createBlock(_component_v_uni_view, {
                                            key: 1,
                                            class: "right",
                                            onClick: _cache[4] || (_cache[4] = withModifiers(() => {}, ["stop"]))
                                          }, {
                                            default: withCtx(() => [
                                              (item.status == 0)
                                                ? (openBlock(), createBlock(_component_v_uni_view, {
                                                    key: 0,
                                                    class: "use immediate-use",
                                                    round: true,
                                                    onClick: $event => (useCouponWith(item))
                                                  }, {
                                                    default: withCtx(() => [
                                                      createTextVNode("立即使用")
                                                    ]),
                                                    _: 2
                                                  }, 1032, ["onClick"]))
                                                : (openBlock(), createBlock(_component_v_uni_view, {
                                                    key: 1,
                                                    class: "used"
                                                  }, {
                                                    default: withCtx(() => [
                                                      createTextVNode("已使用")
                                                    ]),
                                                    _: 1
                                                  }))
                                            ]),
                                            _: 2
                                          }, 1024))
                                        : createCommentVNode("", true)
                                    ]),
                                    _: 2
                                  }, 1024)
                                ]),
                                _: 2
                              }, 1024)
                            ]),
                            _: 2
                          }, 1032, ["onClick"]))
                        }), 128))
                      ]),
                      _: 1
                    }))
                  : createCommentVNode("", true)
              ]),
              _: 1
            })
          ]),
          _: 1
        }),
        createVNode(_component_modal, {
          custom: "",
          show: detailModalVisible.value,
          onCancel: closeDetailModal,
          width: "90%"
        }, {
          default: withCtx(() => [
            createVNode(_component_v_uni_view, { class: "modal-content" }, {
              default: withCtx(() => [
                createVNode(_component_v_uni_view, { class: "d-flex font-size-extra-lg text-color-base just-content-center mb-20" }, {
                  default: withCtx(() => [
                    createTextVNode(toDisplayString(coupon.value.title), 1)
                  ]),
                  _: 1
                }),
                createVNode(_component_v_uni_view, { class: "d-flex font-size-sm text-color-base mb-20" }, {
                  default: withCtx(() => [
                    createTextVNode(" 有效期：" + toDisplayString(unref(formatDateTime)(coupon.value.startTime, 'yyyy-MM-dd')) + "-" + toDisplayString(unref(formatDateTime)(coupon.value.endTime, 'yyyy-MM-dd')), 1)
                  ]),
                  _: 1
                }),
                createVNode(_component_v_uni_view, { class: "d-flex font-size-sm text-color-base mb-20" }, {
                  default: withCtx(() => [
                    createTextVNode(" 领取时间：" + toDisplayString(unref(formatDateTime)(coupon.value.createTime)), 1)
                  ]),
                  _: 1
                }),
                createVNode(_component_v_uni_view, { class: "d-flex font-size-sm text-color-base mb-20" }, {
                  default: withCtx(() => [
                    createTextVNode(" 券价值：满" + toDisplayString(coupon.value.least) + "减" + toDisplayString(coupon.value.value), 1)
                  ]),
                  _: 1
                }),
                (activeTabIndex.value == 1)
                  ? (openBlock(), createBlock(_component_v_uni_view, {
                      key: 0,
                      class: "d-flex font-size-sm text-color-base mb-20"
                    }, {
                      default: withCtx(() => [
                        createTextVNode(" 每人限领：" + toDisplayString(coupon.value.limit) + " 张 ", 1)
                      ]),
                      _: 1
                    }))
                  : createCommentVNode("", true),
                createVNode(_component_v_uni_view, { class: "d-flex font-size-sm text-color-base mb-20" }, {
                  default: withCtx(() => [
                    createTextVNode(" 适用范围：" + toDisplayString(typeInfo(coupon.value.type)), 1)
                  ]),
                  _: 1
                }),
                createVNode(_component_v_uni_view, { class: "d-flex font-size-sm text-color-base mb-20" }, {
                  default: withCtx(() => [
                    createTextVNode(" 适用店铺：" + toDisplayString(coupon.value.shopName), 1)
                  ]),
                  _: 1
                }),
                (activeTabIndex.value == 0)
                  ? (openBlock(), createBlock(_component_v_uni_view, {
                      key: 1,
                      class: "d-flex align-items-center just-content-center"
                    }, {
                      default: withCtx(() => [
                        createVNode(_component_v_uni_button, {
                          type: "primary",
                          onClick: useCoupon,
                          class: "use-coupon-btn"
                        }, {
                          default: withCtx(() => [
                            createTextVNode("立即使用")
                          ]),
                          _: 1
                        })
                      ]),
                      _: 1
                    }))
                  : createCommentVNode("", true),
                (activeTabIndex.value == 1)
                  ? (openBlock(), createBlock(_component_v_uni_view, {
                      key: 2,
                      class: "d-flex align-items-center just-content-center"
                    }, {
                      default: withCtx(() => [
                        createVNode(_component_v_uni_button, {
                          type: "primary",
                          onClick: _cache[6] || (_cache[6] = $event => (receive(coupon.value, couponIndex.value))),
                          class: "use-coupon-btn"
                        }, {
                          default: withCtx(() => [
                            createTextVNode("立即领取")
                          ]),
                          _: 1
                        })
                      ]),
                      _: 1
                    }))
                  : createCommentVNode("", true)
              ]),
              _: 1
            })
          ]),
          _: 1
        }, 8, ["show"]),
        createVNode(_component_uv_toast, {
          ref_key: "uToast",
          ref: uToast
        }, null, 512)
      ]),
      _: 1
    }, 8, ["style"])
  ], 64))
}
}

};
const coupons = /*#__PURE__*/_export_sfc(_sfc_main, [['__scopeId',"data-v-ba20411d"]]);

export { coupons as default };
